using System.Text;

namespace LuckyLang.AST.Expression.ValueTyre;

public class IntValue : Value
{
    public IntValue(int                   value) => TheValue = value;
    public override Value PlusValue(Value other)
    {
        if (other is DoubleValue)
        {
            return other.PlusValue(this);
        }
        if (other is IntValue)
        {
            return new IntValue(Int32.Parse(ToString())+Int32.Parse(other.ToString()));
        }
        return null;
    }
    public override string ToString() => TheValue.ToString();
    public override Value MinusValue(Value other)
    {
        if (other is DoubleValue)
            return other.MinusValue(this);
        if (other is IntValue)
            return new IntValue(Int32.Parse(ToString())-Int32.Parse(other.ToString()));
        return null;
    }
    public override Value TimesValue(Value other)
    {
        if (other is DoubleValue)
            return other.TimesValue(this);
        if (other is IntValue)
            return new IntValue(Int32.Parse(ToString())*Int32.Parse(other.ToString()));
        
        if (other is StringValue)
        {
            StringBuilder builder = new StringBuilder(other.ToString());
            for (int i = 0; i < (int)TheValue; i++)
            {
                builder.Append(other);
            }
            return new StringValue(builder.ToString());
        }
        return null;
    }
    public override Value DivideValue(Value other)
    {
        if (other is DoubleValue)
            return other.PlusValue(this);
        if (other is IntValue)
            return new IntValue(Int32.Parse(ToString())/Int32.Parse(other.ToString()));
        return null;
    }
    public override bool LesserValue(Value  other) => (int)TheValue < Int32.Parse(other.ToString());
    public override bool GreaterValue(Value other) => (int)TheValue > Int32.Parse(other.ToString());
    public override bool LessEqValue(Value  other) => (int)TheValue <= Int32.Parse(other.ToString());
    public override bool GreaEqValue(Value  other) => (int)TheValue >= Int32.Parse(other.ToString());
}